package com.library.cxq.servlet;

import com.alibaba.fastjson.JSON;
import com.library.cxq.service.impl.ReaderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class ReaderRegister extends HttpServlet {
    ReaderServiceImpl readerService=new ReaderServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charse=UTF-8");
        PrintWriter out=resp.getWriter();
       Integer reaId=(int)((Math.random()*9+1)*100000);
        String idCard = req.getParameter("idCard");
        String pwd ="123456";//初始密码
        String name = req.getParameter("name");
        Integer age = Integer.parseInt(req.getParameter("age"));
        String phone = req.getParameter("phone");
        double price=0;//初始金额
        boolean register = readerService.register(reaId, idCard, pwd, name, age, phone,price);
        String isregister = JSON.toJSONString("isregister");
        out.print(isregister);
        out.flush();
        out.close();
    }
}
